package com.wing.cabinet.controller.app;


import com.wing.cabinet.model.entity.CellInventoryInoutDetail;
import com.wing.cabinet.model.entity.StorageInventoryInoutDetail;
import com.wing.cabinet.model.entity.UseInventoryInoutDetail;
import com.wing.cabinet.model.response.CellInventoryInoutDetailVO;
import com.wing.cabinet.model.response.StorageInventoryInoutDetailVO;
import com.wing.cabinet.model.response.UseInventoryInoutDetailVO;
import com.wing.cabinet.service.CellInventoryInoutDetailService;
import com.wing.cabinet.service.StorageInventoryInoutDetailService;
import com.wing.cabinet.service.UseInventoryInoutDetailService;
import com.wing.common.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(value = "App-API", tags = "刀柜API")
@RestController("appCabApiController")
@RequestMapping("api/")
public class CabApiController {

    @Autowired
    private StorageInventoryInoutDetailService storageInventoryInoutDetailService;

    @Autowired
    private CellInventoryInoutDetailService cellInventoryInoutDetailService;

    @Autowired
    private UseInventoryInoutDetailService useInventoryInoutDetailService;

    @GetMapping("/getOutNewKnifes")
    @ApiOperation(value = "查询当天的领新数据", notes = "搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "day", value="时间，例如：2023-05-20", defaultValue = "create_time", example = "create_time", dataType = "String", paramType = "query")
    })
    public JsonResult<CellInventoryInoutDetailVO> getOutNewKnives(String day){

        List<CellInventoryInoutDetailVO> list=cellInventoryInoutDetailService.list4app(getParams(day));
        return JsonResult.success(list);
    }

    @GetMapping("/getTempInKnives")
    @ApiOperation(value = "查询当天的暂存存入数据", notes = "搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "day", value="时间，例如：2023-05-20", defaultValue = "create_time", example = "create_time", dataType = "String", paramType = "query")
    })
    public JsonResult<StorageInventoryInoutDetailVO> getTempInKnives(String day){
        List<StorageInventoryInoutDetailVO> list=getInKnifes(day,StorageInventoryInoutDetail.BusinessType.temp,StorageInventoryInoutDetail.OperationType.in);
        return JsonResult.success(list);
    }

    @GetMapping("/getRecycleInKnives")
    @ApiOperation(value = "查询当天的报废存入数据", notes = "搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "day", value="时间，例如：2023-05-20", defaultValue = "create_time", example = "create_time", dataType = "String", paramType = "query")
    })
    public JsonResult<StorageInventoryInoutDetailVO> getRecycleInKnives(String day){
        List<StorageInventoryInoutDetailVO> list=getInKnifes(day,StorageInventoryInoutDetail.BusinessType.recycle,StorageInventoryInoutDetail.OperationType.in);
        return JsonResult.success(list);
    }

    @GetMapping("/getRepairInKnives")
    @ApiOperation(value = "查询当天的报修存入数据", notes = "搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "day", value="时间，例如：2023-05-20", defaultValue = "create_time", example = "create_time", dataType = "String", paramType = "query")
    })
    public JsonResult<StorageInventoryInoutDetailVO> getRepairInKnives(String day){
        List<StorageInventoryInoutDetailVO> list=getInKnifes(day,StorageInventoryInoutDetail.BusinessType.repair,StorageInventoryInoutDetail.OperationType.in);
        return JsonResult.success(list);
    }

    @GetMapping("/getLossKnives")
    @ApiOperation(value = "查询当天的报失数据", notes = "搜索")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "day", value="时间，例如：2023-05-20", defaultValue = "create_time", example = "create_time", dataType = "String", paramType = "query")
    })
    public JsonResult<UseInventoryInoutDetailVO> getLossKnives(String day){
        Map params=getParams(day);
        params.put("businessType", UseInventoryInoutDetail.BusinessType.loss.getValue());
        params.put("operationType",UseInventoryInoutDetail.Type.loss.getValue());
        List<UseInventoryInoutDetailVO> list=useInventoryInoutDetailService.list4app(params);
        return JsonResult.success(list);
    }

    private List<StorageInventoryInoutDetailVO> getInKnifes(String day,StorageInventoryInoutDetail.BusinessType businessType,StorageInventoryInoutDetail.OperationType operationType){
        Map params=getParams(day);
        params.put("businessType",businessType.getValue());
        params.put("operationType",operationType.getValue());
        List<StorageInventoryInoutDetailVO> list=storageInventoryInoutDetailService.list4app(params);
        return list;
    }

    private Map getParams(String day){
        Map<String, Object> params=new HashMap<>();
        params.put("startCreateTime",day+" 00:00:00");
        params.put("endCreateTime",day+" 23:59:59");
        return params;
    }


}


